package kr.co.dayve.site.management.controller;


import kr.co.dayve.site.domain.*;
import kr.co.dayve.site.management.service.CommentService;
import kr.co.dayve.site.management.service.CommunityBoardService;
import kr.co.dayve.site.management.service.DayveService;
import kr.co.dayve.site.management.service.PhotoBoardService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 사진 게시판 컨트롤러
 */
public class PhotoBoardController extends MultiActionController {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PhotoBoardController.class);
    private int maxTitleLength = 10;
    /**
     * Photo Board List 보기
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView photoBoardList(HttpServletRequest request, HttpServletResponse response) throws Exception {
        PhotoBoard board = new PhotoBoard();
        bind(request, board);

        board.setActivate_yn("Y");

        /**
         * Null 에러 방지용 공백 전환
         */
        if(board.getTitle() == null){
            board.setTitle("");
        }

        if(board.getWriter_id() == null){
            board.setWriter_id("");
        }

        if(board.getWriter_nick_name() == null){
            board.setWriter_nick_name("");
        }

        if(board.getContent() == null){
            board.setContent("");
        }


//        logger.info("photoBoardList");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        java.util.List boardList = photoBoardService.getBoardListBySearchword(board);
        String totalCount = photoBoardService.getTotalCountBySearchword(board);
        // 시간 분할.
        PhotoBoard tmpboard= new PhotoBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        String tempTitle="";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (PhotoBoard)boardList.get(i);
            tempTitle = tmpboard.getTitle();
            if(tempTitle.length()>maxTitleLength){
                tempTitle = tempTitle.substring(0,maxTitleLength-1);
                tempTitle = tempTitle.concat("...");
                ((PhotoBoard) boardList.get(i)).setTitle(tempTitle);
            }
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((PhotoBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((PhotoBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((PhotoBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((PhotoBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((PhotoBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }


        int emptyBoard = Integer.parseInt(totalCount) % 5;

//        logger.info("emptyBoard: {}", emptyBoard);


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        ModelAndView mav = new ModelAndView();
        mav.setViewName(request.getParameter("nextTarget"));
        mav.addObject("boardList", boardList);
        mav.addObject("emptyBoard", emptyBoard);

        return mav;
    }

    /**
     * Photo Board 글 수정 페이지로 이동
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */

    public ModelAndView photoBoardUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception{

        PhotoBoard board = new PhotoBoard();
        bind(request, board);

//        logger.info("photoBoardUpdate");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        java.util.List boardList = photoBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = photoBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        PhotoBoard tmpboard= new PhotoBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        String tempTitle="";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (PhotoBoard)boardList.get(i);
            tempTitle = tmpboard.getTitle();
            if(tempTitle.length()>maxTitleLength){
                tempTitle = tempTitle.substring(0,maxTitleLength-1);
                tempTitle = tempTitle.concat("...");
                ((PhotoBoard) boardList.get(i)).setTitle(tempTitle);
            }
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((PhotoBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((PhotoBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((PhotoBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((PhotoBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((PhotoBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        PhotoBoard tempBoard = new PhotoBoard();

        tempBoard = photoBoardService.getBoardByNo(request.getParameter("photo_board_no"));
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }

//        logger.info("getAdd_file_yn                 : {}", tempBoard.getAdd_file_yn());
//        logger.info("getAdd_file_content_type       : {}", tempBoard.getAdd_file_content_type());
//        logger.info("getAdd_file_size               : {}", tempBoard.getAdd_file_size());
//        logger.info("getAdd_file_original_name      : {}", tempBoard.getAdd_file_original_name());
//        logger.info("getAdd_file_temp_name          : {}", tempBoard.getAdd_file_temp_name());

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        ModelAndView mav = new ModelAndView();

        mav.setViewName(request.getParameter("nextTarget"));
        mav.addObject("board", tempBoard);
        mav.addObject("boardList", boardList);
        return mav;
    }

    /**
     * Photo Board 글 수정 실행
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView photoBoardUpdateAction(HttpServletRequest request, HttpServletResponse response) throws Exception{
        PhotoBoard board = new PhotoBoard();
        bind(request, board);

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = df.format(new Date());

        String result = "";

        board.setModify_date(strDate);

        logger.info("photoBoardUpdateAction");
        logger.info("title     : {}", board.getTitle());
        logger.info("id        : {}", board.getWriter_id());
        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());

        String img_changed = request.getParameter("img_changed");

        if(img_changed.equals("no")){               // 파일 변경 없음 -> 이미지 제외한 업로드.
            // ,..
            // ...
            board.setModify_date(strDate);

            result = photoBoardService.updateBoardNotImage(board); // updateBoard 서비스를 호출 결과를 result 에 담는다
        }else if(img_changed.equals("yes")){        // 파일 변경 있음 -> 이미지 포함 업로드 실시.
            // 파일 업로드 시작
            MultipartHttpServletRequest mpRequest = (MultipartHttpServletRequest) request; // HttpServletRequest 를 MultipartHttpServletRequest 로 casting

            MultipartFile mpFile = mpRequest.getFile("fileUp"); // casting 된 request 에서 파일 얻어오기
            if(mpFile.isEmpty()){ // 첨부 파일이 있는지 검사. 없는 경우
                board.setAdd_file_yn("N");
                board.setAdd_thumbnail_yn("N");
                board.setAdd_thumbnail_file_name("");
            }else{                                  // 첨부파일 있는 경우.
                board.setAdd_thumbnail_yn("Y");
                board.setAdd_thumbnail_file_name("");

                String uploadPath = request.getRealPath("/");
                String filePath = getServletContext().getRealPath("/upload/");
                DayveFile file = photoBoardService.uploadFile(mpFile, uploadPath + "/upload/"); // 있다면 파일 업로드 서비스를 수행 (MultipartFile, 업로드 경로)

                if(file.getContentType().contains("image")){ // 파일 형식을 검색 Image 형식이면 썸네일을 만든다
                    File src = new File(uploadPath + "/upload/" + file.getTempFileName()); // 업로드된 이미지 원본 경로
                    File dest = new File(uploadPath + "/upload/thumb/" + file.getTempFileName() + ".jpg"); // 만들 썸네일 이미지 경로

                    String thumbName = photoBoardService.createThumbnail(src, dest, 180, 180);

                    board.setAdd_thumbnail_yn("Y");
                    board.setAdd_thumbnail_file_name(thumbName);

                }else{
                    board.setAdd_thumbnail_yn("N");
                    board.setAdd_thumbnail_file_name("");
                }

                /**
                 * 첨부파일에 관련된 속성들을 도메인에 셋팅
                 */
                board.setAdd_file_yn("Y");
                //            board.setVote("0");
                //            board.setReport("0");
                board.setAdd_file_original_name(file.getFileName());
                board.setAdd_file_temp_name(file.getTempFileName());
                board.setAdd_file_content_type(file.getContentType());
                board.setAdd_file_size(file.getFileSize());
            }
            // 파일 업로드 끝
            board.setModify_date(strDate);

            result = photoBoardService.updateBoard(board); // updateBoard 서비스를 호출 결과를 result 에 담는다
        }

        board.setActivate_yn("Y");
        //검색값 초기화
        board.setTitle("");
        board.setWriter_id("");
        board.setWriter_nick_name("");
        board.setContent("");


        java.util.List boardList = photoBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = photoBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        PhotoBoard tmpboard= new PhotoBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        String tempTitle="";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (PhotoBoard)boardList.get(i);
            tempTitle = tmpboard.getTitle();
            if(tempTitle.length()>maxTitleLength){
                tempTitle = tempTitle.substring(0,maxTitleLength-1);
                tempTitle = tempTitle.concat("...");
                ((PhotoBoard) boardList.get(i)).setTitle(tempTitle);
            }
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((PhotoBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((PhotoBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((PhotoBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((PhotoBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((PhotoBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        return new ModelAndView("redirect:./photoBoardContent.do?&boardno=" + board.getPhoto_board_no() + "&page=" + board.getCurrentPage() + "&token=" + board.getPhoto_board_no() + "&title&writer_id&writer_nick_name&&content");
    }

    /**
     * Photo Board 글 작성 페이지로 이동
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView photoBoardWrite(HttpServletRequest request, HttpServletResponse response) throws Exception{
        PhotoBoard board = new PhotoBoard();
        bind(request, board);

        board.setActivate_yn("Y");
        board.setHitcount("0");
        board.setReply_count("0");
        board.setVote("0");
        board.setReport("0");

//        logger.info("photoBoardWrite");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        java.util.List boardList = photoBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = photoBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        PhotoBoard tmpboard= new PhotoBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        String tempTitle="";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (PhotoBoard)boardList.get(i);
            tempTitle = tmpboard.getTitle();
            if(tempTitle.length()>maxTitleLength){
                tempTitle = tempTitle.substring(0,maxTitleLength-1);
                tempTitle = tempTitle.concat("...");
                ((PhotoBoard) boardList.get(i)).setTitle(tempTitle);
            }
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((PhotoBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((PhotoBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((PhotoBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((PhotoBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((PhotoBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());
        return new ModelAndView(request.getParameter("nextTarget"), "boardList", boardList);
    }


    /**
     * Photo Board 글 작성 실행
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView photoBoardWriteAction(HttpServletRequest request, HttpServletResponse response) throws Exception{

        PhotoBoard board = new PhotoBoard();
        bind(request, board);

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = df.format(new Date());

        logger.info("photoBoardWriteAction");
        logger.info("title     : {}", board.getTitle());
        logger.info("id        : {}", board.getWriter_id());
        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        // 파일 업로드 시작
        MultipartHttpServletRequest mpRequest = (MultipartHttpServletRequest) request; // HttpServletRequest 를 MultipartHttpServletRequest 로 casting

        MultipartFile mpFile = mpRequest.getFile("fileUp"); // casting 된 request 에서 파일 얻어오기

        if(mpFile.isEmpty()){ // 첨부 파일이 있는지 검사
            board.setAdd_file_yn("N");
            board.setAdd_thumbnail_yn("N");
            board.setAdd_thumbnail_file_name("");
        }else{
            board.setAdd_thumbnail_yn("Y");
            board.setAdd_thumbnail_file_name("");

            String uploadPath = request.getRealPath("/");
            String filePath = getServletContext().getRealPath("/upload/");
            DayveFile file = photoBoardService.uploadFile(mpFile, uploadPath + "/upload/"); // 있다면 파일 업로드 서비스를 수행 (MultipartFile, 업로드 경로)

            if(file.getContentType().contains("image")){ // 파일 형식을 검색 Image 형식이면 썸네일을 만든다
                File src = new File(uploadPath + "/upload/" + file.getTempFileName()); // 업로드된 이미지 원본 경로
                File dest = new File(uploadPath + "/upload/thumb/" + file.getTempFileName() + ".jpg"); // 만들 썸네일 이미지 경로

                String thumbName = photoBoardService.createThumbnail(src, dest, 180, 180);

                board.setAdd_thumbnail_yn("Y");
                board.setAdd_thumbnail_file_name(thumbName);

            }else{
                board.setAdd_thumbnail_yn("N");
                board.setAdd_thumbnail_file_name("");
            }

            /**
             * 첨부파일에 관련된 속성들을 도메인에 셋팅
             */
            board.setAdd_file_yn("Y");
            board.setVote("0");
            board.setReport("0");
            board.setAdd_file_original_name(file.getFileName());
            board.setAdd_file_temp_name(file.getTempFileName());
            board.setAdd_file_content_type(file.getContentType());
            board.setAdd_file_size(file.getFileSize());
        }
        // 파일 업로드 끝

        String result = "";

        board.setHitcount("0");
        board.setReply_count("0");
        board.setVote("0");
        board.setNegative("0");
        board.setReport("0");
        board.setActivate_yn("Y");
        board.setRegister_date(strDate);
        board.setModify_date(strDate);

        result = photoBoardService.writeBoard(board); // writeBoard 서비스를 호출 결과를 result 에 담는다

        java.util.List boardList = photoBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = photoBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        PhotoBoard tmpboard= new PhotoBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        String tempTitle="";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (PhotoBoard)boardList.get(i);
            tempTitle = tmpboard.getTitle();
            if(tempTitle.length()>maxTitleLength){
                tempTitle = tempTitle.substring(0,maxTitleLength-1);
                tempTitle = tempTitle.concat("...");
                ((PhotoBoard) boardList.get(i)).setTitle(tempTitle);
            }
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((PhotoBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((PhotoBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((PhotoBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((PhotoBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((PhotoBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        return new ModelAndView("redirect:" + request.getParameter("nextTarget"), "boardList", boardList);
    }

    /**
     * Photo Board 글 삭제
     * activate_yn = n
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */

    public ModelAndView photoBoardDelete(HttpServletRequest request, HttpServletResponse response) throws Exception{
        PhotoBoard board = new PhotoBoard();
        bind(request, board);

        board.setPhoto_board_no(request.getParameter("photo_board_no"));
        board.setWriter_id(request.getParameter("writer_id"));
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = df.format(new Date());
        board.setModify_date(strDate);

        String result = "";

        board.setActivate_yn("N");

        logger.info("photoBoardDelete");
        logger.info("title     : {}", board.getTitle());
        logger.info("id        : {}", board.getWriter_id());
        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());

        result = photoBoardService.deleteBoard(board); // deleteBoard 서비스를 호출 결과를 result 에 담는다

        board.setActivate_yn("Y");
        board.setWriter_id(""); // 검색값 초기화
        java.util.List boardList = photoBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = photoBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        PhotoBoard tmpboard= new PhotoBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        String tempTitle="";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (PhotoBoard)boardList.get(i);
            tempTitle = tmpboard.getTitle();
            if(tempTitle.length()>maxTitleLength){
                tempTitle = tempTitle.substring(0,maxTitleLength-1);
                tempTitle = tempTitle.concat("...");
                ((PhotoBoard) boardList.get(i)).setTitle(tempTitle);
            }
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((PhotoBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((PhotoBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((PhotoBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((PhotoBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((PhotoBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        return new ModelAndView(request.getParameter("nextTarget"), "boardList", boardList);
    }


    /**
     * Vote Method 게시물 추천 하기
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView photoBoardVote(HttpServletRequest request, HttpServletResponse response) throws Exception{
        PhotoBoard board = new PhotoBoard();
        bind(request, board);

        Vote vote  = new Vote();                            // 추천 용도. (중복 추천 불가)
        String voted = "";
        HttpSession session = request.getSession(false);
        String memberId = (String)session.getAttribute("userId");       // 글번호 세팅
        vote.setContent_no(request.getParameter("boardno"));            // 게시글번호 세팅
        vote.setUser_id(memberId);                                      // 사용자 아이디 세팅
        String checkDuplicate = photoBoardService.checkDuplicateVote(vote);
        String voteResult = "";

        board.setPhoto_board_no(request.getParameter("boardno")); // GET 방식으로 받아온 boardno 파라미터를 도메인에 셋팅
        board.setCurrentPage(Integer.parseInt(request.getParameter("page"))); // GET 방식으로 받아온 page 파라미터 CurrenPage 에 셋팅


        board.setActivate_yn("Y");

//        logger.info("photoBoardVote");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        java.util.List boardList = photoBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = photoBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        PhotoBoard tmpboard= new PhotoBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        String tempTitle="";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (PhotoBoard)boardList.get(i);
            tempTitle = tmpboard.getTitle();
            if(tempTitle.length()>maxTitleLength){
                tempTitle = tempTitle.substring(0,maxTitleLength-1);
                tempTitle = tempTitle.concat("...");
                ((PhotoBoard) boardList.get(i)).setTitle(tempTitle);
            }
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((PhotoBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((PhotoBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((PhotoBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((PhotoBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((PhotoBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }


        // 줄바꿈 처리
        PhotoBoard tempBoard = new PhotoBoard();

        String tempContent;

        tempBoard = photoBoardService.getBoardByNo(request.getParameter("boardno")); // 임시 도메인에 받아온 도메인 리스트에서 첫번째를 주입한다.

        tempContent = tempBoard.getContent(); // 게시물 부분을 임시 String 에 넣는다
        tempContent.replaceAll("\n", "<br>"); // 줄바꿈 처리를 한다.
        tempContent.replaceAll("\u0020", "&nbsp;"); // 스페이스바 공백 처리를 한다.

        tempBoard.setContent(tempContent); // 임시 String 을 임시 객체에 다시 넣는다

        // 줄바꿈 처리 끝
        // 시간 분할
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }



// 추천 체크
        if(checkDuplicate.equals("0")){
            //게시물 테이블 추천 카운트 업데이트
            int voteCount = Integer.parseInt(tempBoard.getVote());
            voteCount++;
            tempBoard.setVote(Integer.toString(voteCount));
            tempBoard.setPhoto_board_no(request.getParameter("boardno"));
            String voteCountResult = photoBoardService.updateVoteCount(tempBoard);
            // 추천자 리스트에 추가.
            voteResult = photoBoardService.insertVoterToList(vote);
            voted = "false";
        }else{
            // 중복 추천.. 이미 추천하셨습니다.
            voted = "true";
        }

        /**
         *
         * Comment 담아오기
         *
         */

        Comment comment = new Comment();
        comment.setBoard_no(request.getParameter("boardno"));
        comment.setComment_db_name("MYHISTORY_PHOTO_BOARD_COMMENT");
        comment.setActivate_yn("Y");

        java.util.List commentList = commentService.getCommentListByBoardNo(comment);
        String commentCount = commentService.getTotalCountByNo(comment);


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        request.setAttribute("commentCount", commentCount);

        ModelAndView mav = new ModelAndView();
        mav.setViewName("redirect:photoBoardContent.do?boardno=" + request.getParameter("boardno") + "&page=" + request.getParameter("page") + "&token=" + request.getParameter("boardno") + "&title&writer_id&writer_nick_name&&content");
        mav.addObject("board", tempBoard);
        mav.addObject("boardList", boardList);
        mav.addObject("commentList", commentList);
        mav.addObject("voted", voted);
        return mav;
    }

    /**
     * Negative Method 게시물 비추천 하기
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView photoBoardNegative(HttpServletRequest request, HttpServletResponse response) throws Exception{
        PhotoBoard board = new PhotoBoard();
        bind(request, board);

        board.setPhoto_board_no(request.getParameter("boardno")); // GET 방식으로 받아온 boardno 파라미터를 도메인에 셋팅
        board.setCurrentPage(Integer.parseInt(request.getParameter("page"))); // GET 방식으로 받아온 page 파라미터 CurrenPage 에 셋팅


        board.setActivate_yn("Y");

//        logger.info("photoBoardNegative");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        java.util.List boardList = photoBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = photoBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        PhotoBoard tmpboard= new PhotoBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        String tempTitle="";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (PhotoBoard)boardList.get(i);
            tempTitle = tmpboard.getTitle();
            if(tempTitle.length()>maxTitleLength){
                tempTitle = tempTitle.substring(0,maxTitleLength-1);
                tempTitle = tempTitle.concat("...");
                ((PhotoBoard) boardList.get(i)).setTitle(tempTitle);
            }
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((PhotoBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((PhotoBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((PhotoBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((PhotoBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((PhotoBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }


        // 줄바꿈 처리
        PhotoBoard tempBoard = new PhotoBoard();

        String tempContent;

        tempBoard = photoBoardService.getBoardByNo(request.getParameter("boardno")); // 임시 도메인에 받아온 도메인 리스트에서 첫번째를 주입한다.

        tempContent = tempBoard.getContent(); // 게시물 부분을 임시 String 에 넣는다
        tempContent.replaceAll("\n", "<br>"); // 줄바꿈 처리를 한다.
        tempContent.replaceAll("\u0020", "&nbsp;"); // 스페이스바 공백 처리를 한다.

        tempBoard.setContent(tempContent); // 임시 String 을 임시 객체에 다시 넣는다

        // 줄바꿈 처리 끝
        //시간분할
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }


        // 비추천 업데이트
        int negativeCount = Integer.parseInt(tempBoard.getNegative());
        negativeCount++;
        tempBoard.setNegative(Integer.toString(negativeCount));
        tempBoard.setPhoto_board_no(request.getParameter("boardno"));

        String negativeCountResult = photoBoardService.updateNegativeCount(tempBoard);


        /**
         *
         * Comment 담아오기
         *
         */

        Comment comment = new Comment();
        comment.setBoard_no(request.getParameter("boardno"));
        comment.setComment_db_name("MYHISTORY_PHOTO_BOARD_COMMENT");
        comment.setActivate_yn("Y");

        java.util.List commentList = commentService.getCommentListByBoardNo(comment);
        String commentCount = commentService.getTotalCountByNo(comment);


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        request.setAttribute("commentCount", commentCount);

        ModelAndView mav = new ModelAndView();
        mav.setViewName("redirect:photoBoardContent.do?boardno=" + request.getParameter("boardno") + "&page=" + request.getParameter("page") + "&token=" + request.getParameter("boardno") + "&title&writer_id&writer_nick_name&&content");
        mav.addObject("board", tempBoard);
        mav.addObject("boardList", boardList);
        mav.addObject("commentList", commentList);
        return mav;
    }

    /**
     * Report Method 게시물 신고 하기
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView photoBoardReport(HttpServletRequest request, HttpServletResponse response) throws Exception{
//        PhotoBoard board = new PhotoBoard();
//        bind(request, board);

        Report report = new Report();
        // reasonKey , reasonDetail, user_id, contentno
        /**
         * Session 이 존재하면 반환 없을시 Null 을 반환
         */
        HttpSession session = request.getSession(false);
        String memberId = (String)session.getAttribute("userId");

        report.setUser_id(memberId);
        report.setContent_no(request.getParameter("boardno"));
        report.setReason_code(request.getParameter("reasonKey"));
        report.setReason_detail(request.getParameter("reasonDetail"));
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = df.format(new Date());
        report.setReport_date(strDate);





        // 줄바꿈 처리
        PhotoBoard tempBoard = new PhotoBoard();

        String tempContent;

        tempBoard = photoBoardService.getBoardByNo(request.getParameter("boardno")); // 임시 도메인에 받아온 도메인 리스트에서 첫번째를 주입한다.

        tempContent = tempBoard.getContent(); // 게시물 부분을 임시 String 에 넣는다
        tempContent.replaceAll("\n", "<br>"); // 줄바꿈 처리를 한다.
        tempContent.replaceAll("\u0020", "&nbsp;"); // 스페이스바 공백 처리를 한다.

        tempBoard.setContent(tempContent); // 임시 String 을 임시 객체에 다시 넣는다
        // 줄바꿈 처리 끝

        // 시간분할
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
//            logger.info("date_part_year   : {}", date_part_year);
//            logger.info("date_part_month   : {}", date_part_month);
//            logger.info("date_part_day   : {}", date_part_day);
//            logger.info("date_part_hour   : {}", date_part_hour);
//            logger.info("date_part_minute   : {}", date_part_minute);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }

        //신고 업데이트
        int reportCount = Integer.parseInt(tempBoard.getReport());
        reportCount++;
        tempBoard.setReport(Integer.toString(reportCount));
        tempBoard.setPhoto_board_no(request.getParameter("boardno"));

        String reportCountResult = photoBoardService.updateReportCount(tempBoard);
        String reportResult = photoBoardService.photoBoardReport(report);

        /**
         *
         * Comment 담아오기
         *
         */

        Comment comment = new Comment();
        comment.setBoard_no(request.getParameter("boardno"));
        comment.setComment_db_name("MYHISTORY_PHOTO_BOARD_COMMENT");
        comment.setActivate_yn("Y");

        java.util.List commentList = commentService.getCommentListByBoardNo(comment);
        String commentCount = commentService.getTotalCountByNo(comment);


//        request.setAttribute("param", request);
//        request.setAttribute("totalRow", totalCount);
//        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
//        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

//        request.setAttribute("commentCount", commentCount);

        ModelAndView mav = new ModelAndView();
//        mav.setViewName("redirect:photoBoardContent.do?boardno=" + request.getParameter("boardno") + "&page=" + request.getParameter("page") + "&title&writer_id&writer_nick_name&&content");
        mav.setViewName("photoReport");
        mav.addObject("baord", tempBoard);
        mav.addObject("closing", "closing");
        mav.addObject("commentList", commentList);
        return mav;
    }

    /**
     * Photo Board 글내용 보기
     *
     * 첨부파일 add_file_yn 검사하여 있다면 다운로드 가능
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView photoBoardContent(HttpServletRequest request, HttpServletResponse response) throws Exception{

        PhotoBoard board = new PhotoBoard();
        bind(request, board);

        /**
         * Null 에러 방지용 공백 전환
         */
        if(request.getParameter("boardno") == null){
            return new ModelAndView("redirect:photoBoardList.do");
        }

        if(request.getParameter("page") == null){
            return new ModelAndView("redirect:photoBoardList.do");
        }

        board.setPhoto_board_no(request.getParameter("boardno")); // GET 방식으로 받아온 boardno 파라미터를 도메인에 셋팅
        board.setCurrentPage(Integer.parseInt(request.getParameter("page"))); // GET 방식으로 받아온 page 파라미터 CurrenPage 에 셋팅

        String voted = request.getParameter("voted");
        /**
         * 게시물 아래에 보여질 목록은 boardList 에 담아 넘긴다.
         * 게시물 내용은 photo_board_no 을 이용해 board 에 받아 넘긴다.
         */

        board.setActivate_yn("Y");

//        logger.info("photoBoardContent");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        java.util.List boardList = photoBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = photoBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        PhotoBoard tmpboard= new PhotoBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        String tempTitle="";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (PhotoBoard)boardList.get(i);
            tempTitle = tmpboard.getTitle();
            if(tempTitle.length()>maxTitleLength){
                tempTitle = tempTitle.substring(0,maxTitleLength-1);
                tempTitle = tempTitle.concat("...");
                ((PhotoBoard) boardList.get(i)).setTitle(tempTitle);
            }
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((PhotoBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((PhotoBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((PhotoBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((PhotoBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((PhotoBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        // 줄바꿈 처리
        PhotoBoard tempBoard = new PhotoBoard();

        String tempContent;

        tempBoard = photoBoardService.getBoardByNo(request.getParameter("boardno")); // 파라미터에서 받아온 게시물 번호로 보드 객체를 받아온다

        tempContent = tempBoard.getContent().replace("\r\n", "<br>"); // 게시물 부분을 임시 String 에 넣는다 줄바꿈 처리
        /**
         tempContent.replaceAll("\n", "<br>"); // 줄바꿈 처리를 한다.
         tempContent.replaceAll("\u0020", "&nbsp;"); // 스페이스바 공백 처리를 한다.
         *
         */
        tempBoard.setContent(tempContent); // 임시 String 을 임시 객체에 다시 넣는다

        HttpSession check = request.getSession(false);

        String sessionToken;
        String formToken;

        if((String)check.getAttribute("sessionToken") == null){
             sessionToken = "";
        }else{
            sessionToken = (String)check.getAttribute("sessionToken");
        }

        if(request.getParameter("token") == null){
            formToken = "";
        }else{
            formToken = request.getParameter("token");
        }




        // hitcount 증가
        int hitCount = Integer.parseInt(tempBoard.getHitcount());
        if(sessionToken.equals(formToken)){
            /**
             * request 로부터 넘어온 token 과 sessionToken 이 일치하면 hitcount를 증가하지 않는다.
             */

        }else{
            hitCount++;
            check.setAttribute("sessionToken", formToken);
            /**
             * hitcount 증가 후
             * 어느 페이지로부터 온 token 인지를 sessionToken 에 기록한다.
             * 같은 페이지에서 넘어왔다면 sessionToken 과 request 의 token 이 같기때문에 위의 if문이 실행된다.
             */

        }

        tempBoard.setHitcount(Integer.toString(hitCount));
        tempBoard.setPhoto_board_no(request.getParameter("boardno"));

        String HitCountResult = photoBoardService.updateHitCount(tempBoard);
        // 줄바꿈 처리 끝
        //시간분할
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }


        /**
         *
         * Comment 담아오기
         *
         */

        Comment comment = new Comment();
        comment.setBoard_no(request.getParameter("boardno"));
        comment.setComment_db_name("MYHISTORY_PHOTO_BOARD_COMMENT");
        comment.setActivate_yn("Y");

        java.util.List commentList = commentService.getCommentListByBoardNo(comment);
        String commentCount = commentService.getTotalCountByNo(comment);


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        request.setAttribute("commentCount", commentCount);

        /**
         * List 에 담은 댓글 내용들 줄바꿈 처리 하기
         */
        for(int i=0;i<commentList.size();i++){
            comment = (Comment)commentList.get(i);
            comment.setContent(comment.getContent().replace("\r\n", "<br>"));
            commentList.set(i, comment);
        }


        ModelAndView mav = new ModelAndView();
        mav.setViewName(request.getParameter("nextTarget"));
        mav.addObject("board", tempBoard);
        mav.addObject("boardList", boardList);
        mav.addObject("commentList", commentList);
        mav.addObject("voted", voted);
        return mav;
    }



    ///////////////////////////////////////
    // Spring Framework Setter Injection //
    ///////////////////////////////////////

    private DayveService dayveService;
    private LocaleResolver localeResolver;
    private CommentService commentService;
    private CommunityBoardService communityBoardService;
    private PhotoBoardService photoBoardService;

    public void setLocaleResolver(LocaleResolver localeResolver) {
        this.localeResolver = localeResolver;
    }

    public void setCommentService(CommentService commentService) {
        this.commentService = commentService;
    }

    public void setDayveService(DayveService dayveService) {
        this.dayveService = dayveService;
    }

    public void setCommunityBoardService(CommunityBoardService communityBoardService) {
        this.communityBoardService = communityBoardService;
    }

    public void setPhotoBoardService(PhotoBoardService photoBoardService) {
        this.photoBoardService = photoBoardService;
    }
}
